@@ -93,18 +93,18 @@ class MissionsController < ApplicationController |
||
| 93 | 93 |
end |
| 94 | 94 |
|
| 95 | 95 |
def take_agent_role |
| 96 |
- mission = Mission.friendly.find(params[:id]) |
|
| 97 |
- agent = mission.mission_agents.friendly.find(params[:agent]) |
|
| 98 |
- candidate = MissionCandidate.create!(user: current_user, mission_agent: agent, status: 1, mode: 'take_agent_role') |
|
| 99 |
- agent.user = current_user |
|
| 100 |
- respond_to do |format| |
|
| 96 |
+ if user_signed_in? |
|
| 97 |
+ mission = Mission.friendly.find(params[:id]) |
|
| 98 |
+ agent = mission.mission_agents.friendly.find(params[:agent]) |
|
| 99 |
+ candidate = MissionCandidate.create!(user: current_user, mission_agent: agent, status: 1, mode: 'take_agent_role') |
|
| 100 |
+ agent.user = current_user |
|
| 101 | 101 |
if agent.save |
| 102 |
- format.html { redirect_to mission_agent_details_path(mission, agent), notice: (t 'mission.take_agent_profile_confirmation') }
|
|
| 103 |
- format.json { head :no_content }
|
|
| 102 |
+ redirect_to mission_agent_details_path(mission, agent), notice: (t 'mission.take_agent_profile_confirmation') |
|
| 104 | 103 |
else |
| 105 |
- format.html { redirect_to mission_agent_details_path(mission, agent), alert: (t 'mission.take_agent_profile_error') }
|
|
| 106 |
- format.json { render json: @mission.errors, status: :unprocessable_entity }
|
|
| 104 |
+ redirect_to mission_agent_details_path(mission, agent), alert: (t 'mission.take_agent_profile_error') |
|
| 107 | 105 |
end |
| 106 |
+ else |
|
| 107 |
+ redirect_to new_user_session_path, notice: (t 'user.not_logged_in') |
|
| 108 | 108 |
end |
| 109 | 109 |
end |
| 110 | 110 |
|
@@ -6,6 +6,8 @@ en: |
||
| 6 | 6 |
step: 'Step' |
| 7 | 7 |
new_mission: 'New Mission' |
| 8 | 8 |
no_missions_yet: 'There are no missions yet. Create the first.' |
| 9 |
+ take_agent_role: 'Take Agent Role' |
|
| 10 |
+ take_agent_profile_confirmation: 'You have taken the agent role' |
|
| 9 | 11 |
step: |
| 10 | 12 |
validated: 'Validated' |
| 11 | 13 |
step_validated: 'Step validated' |
@@ -56,4 +58,6 @@ en: |
||
| 56 | 58 |
add_validation: 'Add Validation' |
| 57 | 59 |
launch: |
| 58 | 60 |
before_launch: 'Before Launch Tips' |
| 59 |
- before_launch_help: '<p>Check out this tips for some things to do before launching your mission.</p><ul><li>Review Your mission in the public view</li><li>Make sure you can deliver the rewards you promisse</li><li>Review agents and make sure everyone has steps with at least one validation</li></ul>' |
|
| 61 |
+ before_launch_help: '<p>Check out this tips for some things to do before launching your mission.</p><ul><li>Review Your mission in the public view</li><li>Make sure you can deliver the rewards you promisse</li><li>Review agents and make sure everyone has steps with at least one validation</li></ul>' |
|
| 62 |
+ user: |
|
| 63 |
+ not_logged_in: 'Please login first before completing this action.' |
@@ -6,6 +6,8 @@ pt-BR: |
||
| 6 | 6 |
step: 'Passo' |
| 7 | 7 |
new_mission: 'Nova Missão' |
| 8 | 8 |
no_missions_yet: 'Não existem missões ainda. Crie a primeira.' |
| 9 |
+ take_agent_role: 'Pegar o papel de agente' |
|
| 10 |
+ take_agent_profile_confirmation: 'Você se registrou para o papel de agente' |
|
| 9 | 11 |
step: |
| 10 | 12 |
validated: 'Validado' |
| 11 | 13 |
step_validated: 'Passo validado' |
@@ -56,4 +58,6 @@ pt-BR: |
||
| 56 | 58 |
add_validation: 'Adicionar Validação' |
| 57 | 59 |
launch: |
| 58 | 60 |
before_launch: 'Before Launch Tips' |
| 59 |
- before_launch_help: '<p>Check out this tips for some things to do before launching your mission.</p><ul><li>Review Your mission in the public view</li><li>Make sure you can deliver the rewards you promisse</li><li>Review agents and make sure everyone has steps with at least one validation</li></ul>' |
|
| 61 |
+ before_launch_help: '<p>Check out this tips for some things to do before launching your mission.</p><ul><li>Review Your mission in the public view</li><li>Make sure you can deliver the rewards you promisse</li><li>Review agents and make sure everyone has steps with at least one validation</li></ul>' |
|
| 62 |
+ user: |
|
| 63 |
+ not_logged_in: 'Por favor entre no site antes de executar está ação.' |
@@ -1,4 +1,4 @@ |
||
| 1 |
-@mission_editor |
|
| 1 |
+@mission_editor @mission |
|
| 2 | 2 |
Feature: Mission Editor |
| 3 | 3 |
In order to create a mission |
| 4 | 4 |
As an Mission Director |
@@ -1,4 +1,4 @@ |
||
| 1 |
-@mission_view |
|
| 1 |
+@mission_view @mission |
|
| 2 | 2 |
Feature: Missions |
| 3 | 3 |
In order to browse for missions |
| 4 | 4 |
As an Avalanche Agent |
@@ -98,5 +98,35 @@ Feature: Missions |
||
| 98 | 98 |
And I should see "Open the vault" |
| 99 | 99 |
And I should see "Get the money" |
| 100 | 100 |
And I should see "Leave the bank" |
| 101 |
+ |
|
| 102 |
+ Scenario: Take agent role from agents page |
|
| 103 |
+ Given the user "Monty" "Cantsin" with email "monty_cantsin@canada.com" and password "12345678" exists and is logged in |
|
| 104 |
+ And I go to the missions page |
|
| 105 |
+ And I click in the link "Bank Robbery" |
|
| 106 |
+ And within "#mission-tabs-nav" I click in the link "Agents" |
|
| 107 |
+ And within "#agent-mr-pink" I should see "No Agent Selected" |
|
| 108 |
+ When within "#agent-mr-pink" I click in the link "Apply For Position" |
|
| 109 |
+ Then within "h2" I should see "Mr. Pink" |
|
| 110 |
+ Then I should see "You have taken the agent role" |
|
| 111 |
+ And within ".assigned-agent-role" I should see "Monty Cantsin" |
|
| 112 |
+ |
|
| 113 |
+ Scenario: Take agent role from agent page |
|
| 114 |
+ Given the user "Monty" "Cantsin" with email "monty_cantsin@canada.com" and password "12345678" exists and is logged in |
|
| 115 |
+ And I go to the missions page |
|
| 116 |
+ And I click in the link "Bank Robbery" |
|
| 117 |
+ And within "#mission-tabs-nav" I click in the link "Agents" |
|
| 118 |
+ And within "#agent-mr-pink" I should see "No Agent Selected" |
|
| 119 |
+ And within "#agent-mr-pink" I click in the link "Mr. Pink" |
|
| 120 |
+ Then within "h2" I should see "Mr. Pink" |
|
| 121 |
+ And within ".open-agent-role" I should see "This agent role is open for the first user that apply for it." |
|
| 122 |
+ When within ".open-agent-role" I click in the link "Take Agent Role" |
|
| 123 |
+ Then I should see "You have taken the agent role" |
|
| 124 |
+ And within ".assigned-agent-role" I should see "Monty Cantsin" |
|
| 101 | 125 |
|
| 102 |
- |
|
| 126 |
+ Scenario: User not logged in try to take agent role |
|
| 127 |
+ Given I am not logged in |
|
| 128 |
+ And I go to the missions page |
|
| 129 |
+ And I click in the link "Bank Robbery" |
|
| 130 |
+ And within "#mission-tabs-nav" I click in the link "Agents" |
|
| 131 |
+ When within "#agent-mr-pink" I click in the link "Apply For Position" |
|
| 132 |
+ Then I should see "Please login first before completing this action." |
@@ -38,6 +38,7 @@ Then(/^I log out$/) do |
||
| 38 | 38 |
# end |
| 39 | 39 |
end |
| 40 | 40 |
|
| 41 |
+# Create user |
|
| 41 | 42 |
Given(/^the user "(.*?)" "(.*?)" with email "(.*?)" and password "(.*?)" exists$/) do |arg1, arg2, arg3, arg4| |
| 42 | 43 |
user_hash = { "first_name" => arg1, "last_name" => arg2, "email" => arg3, "password" => arg4 }
|
| 43 | 44 |
if User.find_by_email(arg3) == nil |
@@ -48,6 +49,22 @@ Given(/^the user "(.*?)" "(.*?)" with email "(.*?)" and password "(.*?)" exists$ |
||
| 48 | 49 |
end |
| 49 | 50 |
end |
| 50 | 51 |
|
| 52 |
+# Create and log in user |
|
| 53 |
+Given(/^the user "(.*?)" "(.*?)" with email "(.*?)" and password "(.*?)" exists and is logged in$/) do |arg1, arg2, arg3, arg4| |
|
| 54 |
+ user_hash = { "first_name" => arg1, "last_name" => arg2, "email" => arg3, "password" => arg4 }
|
|
| 55 |
+ if User.find_by_email(arg3) == nil |
|
| 56 |
+ user = FactoryGirl.create(:user, user_hash) |
|
| 57 |
+ end |
|
| 58 |
+ if User.last.email != arg3 |
|
| 59 |
+ return false |
|
| 60 |
+ end |
|
| 61 |
+ visit new_user_session_path |
|
| 62 |
+ fill_in "user_email", :with => arg1 |
|
| 63 |
+ fill_in "user_password", :with => arg2 |
|
| 64 |
+ click_button "Submit" |
|
| 65 |
+ login_as user, scope: :user |
|
| 66 |
+end |
|
| 67 |
+ |
|
| 51 | 68 |
# Fixes for devise post bug |
| 52 | 69 |
|
| 53 | 70 |
Then(/^I log in with the email "(.*?)" and password "(.*?)"$/) do |arg1, arg2| |